﻿/**************************************************************************
创建时间:	2020/5/16 23:59:25    
作	  者:	张存
邮 	  箱:	zhangcunliang@126.com

Copyright (c) zhcun.cn

描	述：默认的数据库配置对象
记	录：
***************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZhCun.DbCore;
using ZhCun.Utils;
using ZhCun.Utils.Helpers;

namespace ZhCun.Win.DB
{
    public class SysConfig : ISysConfig
    {
        static ISysConfig _ConfigObj;

        /// <summary>
        /// 获取配置对象
        /// </summary>
        public static ISysConfig ConfigObj
        {
            set
            {
                if (_ConfigObj == null) _ConfigObj = value;
                else
                {
                    throw new Exception("配置对象只能设置一次");
                }
            }
            get { return _ConfigObj; }
        }

        internal static ISysConfig CreateConfig()
        {
            if (_ConfigObj == null) _ConfigObj = new SysConfig();
            //if (GetConfigHandle != null)
            //{
            //    return GetConfigHandle();
            //}
            return _ConfigObj;
        }

        public string GetConnStr()
        {
            var connStr = ConfigHelper.GetConnectString("Sys.ConnStr");
            return connStr;
            //string dbTypeStr = ConfigHelper.GetAppSettings("Sys.DbType");
            //EnumHelper.StringToEnum(dbTypeStr, out DbType);
            //string ciphertext = ConfigHelper.GetConnectString("Sys.ConnStr");
            //ConnStr = DynamicEncrypty.GetPlaintext("Sys.ConnStr", ciphertext);
        }

        public EmDbType GetDbType()
        {
            string dbTypeStr = ConfigHelper.GetAppSettings("Sys.DbType");
            EmDbType dbType;
            EnumHelper.StringToEnum(dbTypeStr, out dbType);
            return dbType;
        }
    }
}